package com.example.mardan.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mardan.entity.TangshiChapter;
import com.example.read.R;

import java.util.List;

public class TangShiAdapter extends RecyclerView.Adapter<TangShiAdapter.TangShiViewHolder> {
    private List<TangshiChapter.ResultDTO> tangShiList;

    public TangShiAdapter(List<TangshiChapter.ResultDTO> tangShiList) {
        this.tangShiList = tangShiList;
    }

    @NonNull
    @Override
    public TangShiViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_tangshi, parent, false);
        return new TangShiViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull TangShiViewHolder holder, int position) {
        TangshiChapter.ResultDTO tangShi = tangShiList.get(position);
        holder.textViewId.setText(tangShi.getDetailid()+" - "+ tangShi.getName()+ " - "+tangShi.getAuthor());
//        holder.textViewName.setText("Name: " + tangShi.getName());
//        holder.textViewAuthor.setText("Author: " + tangShi.getAuthor());
    }

    @Override
    public int getItemCount() {
        return tangShiList.size();
    }

    static class TangShiViewHolder extends RecyclerView.ViewHolder {
        TextView textViewId;
//        TextView textViewName;
//        TextView textViewAuthor;

        public TangShiViewHolder(@NonNull View itemView) {
            super(itemView);
            textViewId = itemView.findViewById(R.id.textViewId);
//            textViewName = itemView.findViewById(R.id.textViewName);
//            textViewAuthor = itemView.findViewById(R.id.textViewAuthor);
        }
    }
}